<?php  
namespace Admin\Controller;
use Think\Controller;
class UserController extends Controller {

	 //后台登录展示页
     public function login(){
			$this->display();
     }
      //ajax验证验证码-密码
     public function yzdl(){
        $user = D('User')->where('email='.'"'.I('post.email').'"')->find();
            if(!$this->check_yzm(I('post.yzm'))){
                    echo 2;
                  }else if(I('post.password') !== $user['password']){                
                           echo 3;
                  }else{
                     //登录成功后写入cookie
                    cookie('email',$user['email']);    
            }
     } 

    //可以设置验证码大小字数
    public function yzm(){
          $Verify = new \Think\Verify();//实例化
          $Verify->length = 4;//设置验证码字数
          $Verify->entry();//验证码输出
          // $Verify->imageW = 333.33;//设置宽
          // $Verify->imageH = 40;//设置高
          // $Verify->fontSize = 20;//设置字体大小
          // $Verify->userNoise = true;//干扰线
          // $Verify->useZh = true;
            
     }
     //判断验证码是否正确                              
     public function check_yzm($yzm){
          $Verify = new \Think\Verify();//实例化
          $Verify->reset=false;
          if($Verify->check($yzm)){
                  return true;
          }else{
                  return false;
          }
     }
     //修改密码展示页
     public function pass(){
          if($_COOKIE['email']){
               $this->display();
          }else{
               $this->redirect('User/login');
          }
     }
     //接收修改密码的信息
     public function updatePw(){
          $userModel = D('User');
         $user = $userModel->where("email='$_COOKIE[email]'")->find();
          // print_r($user);
          // exit();
          if(I('post.password') !== $user['password']){
              // echo 1;
          }else{
               $a = I('post.newpass');
               $userModel->where("email='$_COOKIE[email]'")->save(['password'=>$a]);
          }   
     }

     //退出清cookie
     public function logout(){
            cookie('email',null);
            $this->redirect('User/login');
     }
     //管理员列表
     public function userlist(){
          $this->display();
     }
     //管理员页
     public  function useradd(){
          $this->display();
     }
}

